local BaseData = require("data.base.BaseData")
local ServerTimeData = class("ServerTimeData", BaseData)

local schema = {}
schema["time"] = {"number", 0} -- 服务器时间戳（毫秒）
ServerTimeData.schema = schema

function ServerTimeData:ctor()
    ServerTimeData.super.ctor(self)
    self._signalHeartBeart = G_NetWorkManager:add(MessageIDConst.ID_S2C_HeartBeat, handler(self, self._s2cHeartBeat))
end

function ServerTimeData:clear()
    self._signalHeartBeart:remove()
    self._signalHeartBeart = nil
end

function ServerTimeData:c2sHeartBeat()
    local id = G_UserData:getBase():getId()
    if id > 0 then   -- 登录了
        G_NetWorkManager:send(MessageIDConst.ID_C2S_HeartBeat, {id = id})
    end
end

function ServerTimeData:_s2cHeartBeat(id, message)
    local time = rawget(message, "time")
    self:setTime(time)
end

return ServerTimeData
